package com.parkingspace.controller;


import com.parkingspace.entity.OrderPlus;
import com.parkingspace.service.IEOrderService;
import com.parkingspace.service.IOrderService;
import com.parkingspace.util.Constants;
import com.parkingspace.util.ResultVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author Gapper
 * @since 2021-05-24
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private IOrderService iOrderService;

    @Resource
    private IEOrderService ieOrderService;

    @PostMapping("addOrder")
    public ResultVO createOrder(Long parkingId,Integer time,Long uid,Long carid,Integer rent){
        ieOrderService.sendDlx(parkingId,uid,Integer.valueOf((time * 60)).toString());
        Integer row = iOrderService.createOrder(parkingId,time,uid,carid,rent);
        if (row != 0){
            return new ResultVO(Constants.OPER_SUCCESS,null,"success");
        }else {
            return new ResultVO(Constants.OPER_FAILURE,null,"failure");
        }
    }

    @PostMapping("getOrder")
    public ResultVO getOrder(Long uid,Integer pageNo,Integer pageSize,String address){
        List<OrderPlus> orderPluses = iOrderService.getOrder(uid,pageNo,pageSize,address);
        return new ResultVO(Constants.OPER_SUCCESS,"",orderPluses);
    }

    @PostMapping("buyforOrder")
    public ResultVO buyForOrder(Long uid,Long orderid,Double price){
        Boolean result = iOrderService.buyForOrder(uid,orderid,price);
        return new ResultVO(Constants.OPER_SUCCESS,"",result);
    }

    @PostMapping("delOrder")
    public ResultVO delOrder(Long orderid){
        boolean b = iOrderService.removeById(orderid);
        return new ResultVO(Constants.OPER_SUCCESS,"",b);
    }
}

